package view.builder;

import java.awt.Dimension;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import view.MainFrame;
import dbinfo.DbInfoDao;

public class DbInfoUIBuilder implements UIBuilder{

	private DbInfoDao dbInfoDao;

	private List<Map<String,String>>dbInfoList;
	
	public DbInfoUIBuilder(){
		dbInfoDao = new DbInfoDao();
		dbInfoList = dbInfoDao.getDbInfo();
	}

	@Override
	public void uiBuild(MainFrame mainFrame) {
		JPanel panel = new JPanel();
		
		String[] columnHeader = {"Name", "Value"};
		String[][] data = new String[dbInfoList.size()][2];
		
		for(int i = 0; i < dbInfoList.size(); i++){
			Map<String, String> map = dbInfoList.get(i);
			Set<String> keySet = map.keySet();
			Iterator<String> iterator = keySet.iterator();
			while(iterator.hasNext()){
				String value = iterator.next();
				data[i][0] = value;
				data[i][1] = map.get(value);
			}	 
		}//end for
		
		JTable table = new JTable(data, columnHeader);
		table.setName("dbInfoTable");
		table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        table.setFillsViewportHeight(true);
        JScrollPane scrollPane = new JScrollPane(table);
        
        mainFrame.add(scrollPane);
	}
}